﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.NetworkInformation;
using TOTTO.FINGERPRINT.VISTA.WsFingerPrint;
//using TOTTO.FINGERPRINT.SERVICIOS.Utilidades.Complementos;

namespace TOTTO.FINGERPRINT.VISTA
{
    /// <summary>
    /// Lógica de interacción para frmParametrosIniciales.xaml
    /// </summary>
    public partial class frmParametrosIniciales : Window
    {
        private TFNT_CENTROSDECOSTO vvCC = null;

        public frmParametrosIniciales()
        {
            InitializeComponent();
            FingerPrintServiceClient p = new FingerPrintServiceClient();
            List<TFNT_EMPRESAS> lasEmpresas = p.mConsultarEmpresas().ToList();
            cmbEmpresas.DisplayMemberPath = "EMP_VNOMBRE";
            cmbEmpresas.SelectedValuePath = "EMP_SID";
            cmbEmpresas.ItemsSource = lasEmpresas;
            
            //No me empecés a criticar el codiguito, apenas estoy desenredando esta joda


            //Llama los adaptadores de red para poder seleccionar con cual se identificará FingerPrint
            var y = (from g in NetworkInterface.GetAllNetworkInterfaces().AsQueryable<NetworkInterface>()
                     where (g.OperationalStatus == OperationalStatus.Up || g.OperationalStatus == OperationalStatus.Down) && (g.NetworkInterfaceType == NetworkInterfaceType.Ethernet || g.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
                     select new { Titulo = g.Name + " || " + g.GetPhysicalAddress().ToString(), g }).OrderBy(x => x.g.NetworkInterfaceType);

            if (y.Count() > 0)
            {
                cmbInterfazRed.DisplayMemberPath = "Titulo";
                cmbInterfazRed.SelectedValuePath = "g";
                cmbInterfazRed.ItemsSource = y.ToList();
            }
            else
            {
                MessageBox.Show("No se encuentran adaptadores de red validos para ejecutar la aplicación");
            }
            
        }

        private void btnConsultar_Click(object sender, RoutedEventArgs e)
        {
            txtCC.Text = txtCC.Text.Trim();
            if (txtCC.Text.Length > 0)
            {
                //Enabled = false;
                FingerPrintServiceClient p = new FingerPrintServiceClient();
                p.mObtieneCC(Convert.ToInt16(cmbEmpresas.SelectedValue), txtCC.Text);
                p.Close();
                p = null;
            }
            else
            {
                MessageBox.Show("Debe ingresar un CC");
            }
        }

        private void btnSalir_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        
    }
}
